package com.ny.interceptor;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
public class MyWebMvcConfig implements WebMvcConfigurer {

    @Resource
    LoginInterceptor loginInterceptor;

    // 注册拦截器并配置拦截规则
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/user/**") // 保护所有用户接口
                .excludePathPatterns("/login")  // 排除登录接口
                .excludePathPatterns("/user/registerUser") // 排除注册接口
                .excludePathPatterns("/user/findUserByEmail") // 排除邮箱查询
                .excludePathPatterns("/user/sendEmailCode") // 排除发送验证码
                .excludePathPatterns("/user/updatePasswordByEmail") // 排除邮箱改密码
                .order(1);
    }
}